using System.Collections;
using UnityEngine;

public class PlayerDashState : PlayerState
{
    public PlayerDashState(PlayerFSM manager, string animationName) : base(manager, animationName) { }

    public override void OnEnter()
    {
        base.OnEnter();
        parameter.isWaitDash = true;
        manager.OnStartCoroutine(DashExitTime());
        manager.OnStartCoroutine(DashWaitTime());

        //屏幕抖动
        GameManager.Instance.CameraShake();

        //冲击波
        GameManager.Instance.PlayRippleEffect(manager.transform.position);
    }

    public override void OnUpdate()
    {
        base.OnUpdate();
        if (parameter.isHurt)
        {
            manager.TransitionState(StateType.Hit);
        }
        if(parameter.isClimb){
            manager.TransitionState(StateType.ClimbBegin);
        }
    }

    public override void OnFixedUpdate()
    {
        base.OnFixedUpdate();

        SetVelocity(parameter.dashPostion.x * parameter.facingDirection, parameter.dashPostion.y);
        //生成影子
        ObjectPool.GetObject(parameter.shadowPrefab);
    
    }

    public override void OnExit()
    {
        base.OnExit();
    }

    IEnumerator DashExitTime()
    {
        yield return new WaitForSeconds(parameter.dashTime); // 等待
        manager.TransitionState(StateType.Idle);
    }

    IEnumerator DashWaitTime()
    {
        yield return new WaitForSeconds(parameter.dashCD); // 等待
        parameter.isWaitDash = false;
    }
}
